package com.fxcalibre.db.beans;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.Hibernate;

import com.fxcalibre.hibernate.GenericCriteria;

@Entity
@Table(name = "PERSON")
public class Person extends HibernateBean
{

	@Id
	@GeneratedValue
	@Column(name = "PERSON_ID")
	private Integer personId;

	@Column(name = "IMDB_ID", nullable = true, unique = true)
	String imdbId;

	@Column(name = "NAME")
	private String name;

	@Column(name = "BIO", nullable = true, length=1000)
	private String bio;

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.person", cascade = CascadeType.ALL)
	Set<Crew> media = new HashSet<Crew>();

	@Override
	public void initialize()
	{
		Hibernate.initialize(getMedia());
	}

	public Integer getPersonId()
	{
		return personId;
	}

	public void setPersonId(Integer personId)
	{
		this.personId = personId;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public String getImdbId()
	{
		return imdbId;
	}

	public void setImdbId(String imdbId)
	{
		this.imdbId = imdbId;
	}

	public Set<Crew> getMedia()
	{
		return media;
	}

	public void setMedia(Set<Crew> media)
	{
		this.media = media;
	}

	public String getBio()
	{
		return bio;
	}

	public void setBio(String bio)
	{
		this.bio = bio;
	}

	public static GenericCriteria crearCriterio()
	{
		return new GenericCriteria(Person.class.getName());
	}

	@Override
	public String toString()
	{
		return "Person [personId=" + personId + ", name=" + name + "]";
	}


}
